#install.packages("lavaan")
library(lavaan)
#install.packages("semTools")
library(semTools)
library(DescTools)
##define the model as the four indicators.  

CFAdata_1<-subset(study1, Obedience>0 & Considerate>0 & Curiosity>0 & Independence>0)

bin.mod <- '
author =~ Obedience + Independence+Considerate+Curiosity'
## Must SIMULTANEOUSLY constrain thresholds, loadings, and intercepts
test.seq <- list(strong = c("thresholds","loadings","intercepts"),
                 means = "means",
                 strict = "residuals")
meq.list <- list()
for (i in 0:length(test.seq)) {
  if (i == 0L) {
    meq.label <- "configural"
    group.equal <- ""
    long.equal <- ""
  } else {
    meq.label <- names(test.seq)[i]
    group.equal <- unlist(test.seq[1:i])
    # long.equal <- unlist(test.seq[1:i])
  }
  
  meq.list[[meq.label]] <- measEq.syntax(configural.model = bin.mod,
                                         data = CFAdata_1,
                                         ordered = c("Obedience",  
                                                     "Independence",
                                                     "Considerate",  
                                                     "Curiosity"),
                                         parameterization = "theta",
                                         ID.fac = "std.lv",
                                         ID.cat = "Wu.Estabrook.2016",
                                         group = "treatment",
                                         group.equal = group.equal,
                                         #longFacNames = longFacNames,
                                         #long.equal = long.equal,
                                         return.fit = TRUE)
}

summary(compareFit(meq.list))

